package com.example.demo;

/**
 * @Author lizhien (zhien.li@nascent.cn)
 * @Date 2020/8/4 19:47
 * @Version 1.0.0
 * @Description com.example.demo
 */

import com.deliveredtechnologies.rulebook.lang.RuleBuilder;
import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ShoppingCartRule extends CoRRuleBook {

    @Override
    public void defineRules() {

        //give 10% off when cart total is greater than $200
        addRule(RuleBuilder.create().withFactType(Cart.class).withResultType(Double.class)
            .when(facts -> facts.getOne().getCartTotal() > 200)
            .then((facts, result) -> result.setValue(20.0))
            .stop()
            .build());
    }
}
